package org.goodsmanager.controller;

import org.goodsmanager.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import jakarta.servlet.http.HttpSession;

/**
 * 用户个人中心控制器
 */
@Controller
@RequestMapping("/profile")
public class ProfileController {
    
    /**
     * 个人中心首页
     */
    @GetMapping("")
    public String profile(Model model, HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }
        
        model.addAttribute("user", user);
        return "shop/profile";
    }
    
    /**
     * 账户安全页面
     */
    @GetMapping("/security")
    public String security(HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }
        
        return "shop/profile-security";
    }
    
    /**
     * 我的收藏页面
     */
    @GetMapping("/wishlist")
    public String wishlist(HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }
        
        return "shop/profile-wishlist";
    }
    
    /**
     * 优惠券页面
     */
    @GetMapping("/coupons")
    public String coupons(HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }
        
        return "shop/profile-coupons";
    }
    
    /**
     * 设置页面
     */
    @GetMapping("/settings")
    public String settings(HttpSession session) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }
        
        return "shop/profile-settings";
    }
}